<template>
  <div class="tags">
    <div
      :class="['item', active === i ? `actived${i}`:  '']"
      v-for="(t, i) in type"
      :key="i"
      @click="change(i)"
    >{{t}}</div>
  </div>
</template>

<script>
export default {
  props: {
    type: {
      type: Array,
      default() {
        return [
          '未检', '阴性', '阳性'
        ]
      }
    },
    value: {
      type: Number,
      default: 0
    },
    disable: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      active: this.value
    }
  },
  watch: {
    value() {
      this.active = this.value
    }
  },
  methods: {
    change(index) {
      if (this.disable) {
        return
      }
      this.active = index
      this.$emit('input', this.active)
      this.$emit('change', this.active)
    }
  }

}
</script>

<style lang="scss" scoped>
.tags {
  display: flex;
  flex-direction: row;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  border: 1px solid #fff;
  border-radius: 4px;
  .item {
    padding: 2px;
    box-sizing: border-box;
  }
  .actived0 {
    background-color: #999;
    color: #fff;
    border-radius: 4px;
  }
  .actived1 {
    background-color: green;
    color: #fff;
    border-radius: 4px;
  }
  .actived2 {
    background-color: rgb(218, 106, 102);
    color: #fff;
    border-radius: 4px;
  }
}
</style>